Intermediate / 1 to 5 years experienced level questions
Intermediate / 1 to 5 years experienced level questions & answers
Ques 1. Explain the difference between Terraform and Ansible.
Terraform is primarily an IaC tool that focuses on provisioning and managing infrastructure, while Ansible is a configuration management tool that automates software provisioning, configuration, and application deployment.
Ques 2. Explain the concept of 'state' in Terraform.
Terraform state is a snapshot of the infrastructure managed by Terraform. It is used to keep track of the resources created and their current state.
Ques 3. How does Terraform manage secrets and sensitive data?
Terraform uses input variables and data sources to manage sensitive information securely. Secrets can be stored in environment variables or using a secret management tool.
Ques 4. Explain the difference between 'terraform apply' and 'terraform plan'.
'terraform plan' shows the execution plan without actually applying the changes, while 'terraform apply' executes the plan and makes the changes to the infrastructure.
Ques 5. How can you create a reusable Terraform module?
To create a reusable Terraform module, define input variables, outputs, and use the module in other configurations. Organize the module in a separate directory with a 'main.tf' file.
Ques 6. How does Terraform handle dependencies between resources?
Terraform automatically handles dependencies between resources. It analyzes the resource graph and provisions resources in the correct order based on dependencies.
Ques 7. Explain the 'count' and 'for_each' meta-arguments in Terraform.
'count' is used to create multiple instances of a resource, while 'for_each' is used for creating multiple instances based on a map or set of values.
Ques 8. Explain the purpose of the 'locals' block in Terraform.
The 'locals' block in Terraform is used to define local variables within a module. These variables are not exposed to the calling module and are only accessible within the module's scope.
Ques 9. How can you manage Terraform remote state locking?
Terraform provides a 'backend' configuration for state storage, and some backends support locking. By configuring the 'lock' option, Terraform can lock the state to prevent concurrent modifications.
Ques 10. How do you handle sensitive data like API keys in Terraform?
Sensitive data like API keys can be stored securely using Terraform's sensitive input variable type or by using a secret management tool. Avoid storing sensitive information directly in configuration files.
Ques 11. What is the difference between 'provisioners' and 'null_resource' in Terraform?
Provisioners are used to execute scripts on a remote resource after creation, while 'null_resource' is a resource type that doesn't directly create infrastructure but can be used to trigger provisioners or other actions.
Ques 12. How does Terraform handle secrets in environment variables?
Terraform automatically masks sensitive information (like secrets) passed through environment variables in command output, making it more secure when dealing with secrets.
Ques 13. Explain the use of 'terraform state mv' command.
'terraform state mv' is used to move a resource instance from one Terraform state file to another. It allows restructuring or reorganizing resources in the state.
Ques 14. Explain the purpose of the 'terraform output' command.
'terraform output' is used to display the values of output variables defined in the Terraform configuration. It helps retrieve information about the infrastructure after it's created.
Ques 15. Explain the difference between 'resource' and 'data' blocks in Terraform.
A 'resource' block is used to define and create infrastructure resources, while a 'data' block is used to fetch and reference data that already exists, such as information from other resources.
Ques 16. How can you manage secret data in Terraform Cloud?
In Terraform Cloud, you can use the 'sensitive' attribute for variables to mark them as sensitive. Terraform Cloud also provides a secure environment for managing sensitive information.
Most helpful rated by users: